/*
 * GPIO.c
 *
 *  Created on: Nov 11, 2013
 *      Author: BlackVolt
 */


#include "derivative.h"
#include "Mytypes.h"
#include "GPIO.h"
#include "ServoMotor.h"
#include "IC_Headers/IC_PwmConfig.h"

void vdfn_GPIO_INIT(void){
	//Turn Off all leds
	LED1_ON;
	LED2_ON;
	LED3_ON;
	LED4_ON;
	//TURN ON only 2 leds
	Var = 0;
	Counter = 0;
	
	
}
#if FreescaleCup

void vdfn_SW_PUSH(){
	
		if(PUSH_BUTT0N_0_PRESSED){
			if(Var == 2){
				LED1_TOG;
				ON_OFF_FLAG = !ON_OFF_FLAG;
				//H_BRIDGE_TOG
				Var = 0;
			}
		Var++;
		}		
	
}
#else
//INTEL CUP CODE

/* Configurate PB like TEST foward_Reverse_Stop*/
void vdfn_IC_SW_Config(){
	
	if(PUSH_BUTT0N_0_PRESSED){
		if(Var == 2){
			if(Counter > 5){
				Counter = 0;
				Flag_Pot_Test = 0;
			}
			vdfn_IC_Cases(Counter);
			Counter++;
			Var = 0;
		}
		Var++;
	}
	
}


void vdfn_IC_Cases(t_Direction State){
	switch(State){
		case _Stop:		//0001
			LED4_ON;
			LED3_OFF;
			LED2_OFF;
			LED1_OFF;
			H_BRIDGE_DIS;
			break;
		case _Foward:	//0010
			LED4_OFF;
			LED3_ON;
			LED2_OFF;
			LED1_OFF;
			break;
		case _Reverse:	//0011
			LED4_ON;
			LED3_ON;
			LED2_OFF;
			LED1_OFF;
			break;
			
		case _TurnRight:  //0100
			LED4_OFF;
			LED3_OFF;
			LED2_ON;
			LED1_OFF;
			break;
		case _TurnLeft:	 //0101
			LED4_ON;
			LED3_OFF;
			LED2_ON;
			LED1_OFF;
			break;
			
		case _Pot_Active: //0110
			LED4_OFF;
			LED3_ON;
			LED2_ON;
			LED1_OFF;
			vdfn_Pot_Active();
		default:
		break;
		
	}
	
}
#endif
